package com.Jin.dao;

import com.Jin.pojo.CarPlate;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface CarPlateDao {

    //查询自己的车牌信息
    @Select("select * from carplates where account=#{account}")
    public List<CarPlate> selectUserPlate(@Param("account") String account);

    //查询自己已拥有车牌
    @Select("select * from carplates where account=#{account} and status=#{status} ")
    public List<CarPlate> selectHave(@Param("account") String account,@Param("status") String status);

    //根据id查询车牌
    @Select("select * from carplates where id=#{id}")
    public CarPlate selectById(int id);

    //查询所有车牌信息
    @Select("select * from carplates")
    public List<CarPlate> selectAllPlate();

    //查询特定状态的车牌
    @Select("select * from carplates where status=#{status}")
    public List<CarPlate> selectPlateByStatus(String status);

    // 申请、添加车牌
    @Insert("insert into carplates(owner, account, licenseNum, number, carType, status) " +
            "VALUES  (#{owner},#{account},#{licenseNum},#{number},#{carType},#{status})")
    public int addPlate(CarPlate carPlate);

    //管理员更新车牌信息
    @Update("update carplates set owner=#{owner},account=#{account},licenseNum=#{licenseNum}," +
            "number=#{number},carType=#{carType},status=#{status} " +
            "where id=#{id}")
    public int updatePlate(CarPlate carPlate);

    //在用户更新信息后，更新owner,及number
    @Update("update carplates set owner=#{owner},number=#{number}  where account=#{account}" )
    public int updateOwner(@Param("account") String account,@Param("owner")String owner,@Param("number")String number);


    //删除车牌记录信息
    @Delete("delete from carplates where id = #{id}")
    public int deletePlate(int id);

    //管理员处理申请
    @Update("update carplates set status=#{status} where id=#{id}")
    public int handleApply(@Param("id")int id,@Param("status")String status);

}

